<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户仪表盘</title>
    <script src="https://cdn.tailwindcss.com"></script>

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" referrerpolicy="no-referrer" />
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
        }
    </style>
    <script src="js/jquery.min.js"></script>

</head>
<body class="bg-gray-50 min-h-screen font-sans" style="display:none">
    <!-- 顶部导航栏 -->
    <header class="bg-white shadow-md sticky top-0 z-50">
        <div class="container mx-auto px-4 py-3 flex items-center justify-between">
            <div class="flex items-center space-x-2">
                <i class="fa fa-tachometer text-primary text-xl"></i>
                <h1 class="text-xl font-bold text-gray-800">用户中心</h1>
            </div>

            <div class="flex items-center space-x-4">
                <span class="text-gray-700">
                    <i class="fa fa-user-circle mr-1"></i> <span class="username"></span>
                </span>
                <a href="javascript:;"  class="text-gray-600 hover:text-red-500 transition-colors" id="user_exit">
                    <i class="fa fa-sign-out"></i> 退出
                </a>
            </div>
        </div>
    </header>

    <!-- 主内容区 -->
    <main class="container mx-auto px-4 py-8">
        <div class="max-w-3xl mx-auto">
            <div class="bg-white rounded-xl shadow-lg p-8 transform hover:shadow-xl transition-all duration-300">
                <div class="text-center mb-6">
                    <div class="w-20 h-20 mx-auto bg-primary/10 rounded-full flex items-center justify-center mb-4">
                        <i class="fa fa-check text-primary text-4xl"></i>
                    </div>
                    <h2 class="text-2xl font-bold text-gray-900 mb-2">登录成功</h2>
                    <p class="text-gray-600">欢迎回来，<span class="username"></span></p>
                </div>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mt-8">
                    <div class="bg-blue-50 rounded-lg p-6 shadow-sm hover:shadow transition-custom">
                        <div class="flex items-center">
                            <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                                <i class="fa fa-user text-blue-600 text-xl"></i>
                            </div>
                            <div>
                                <h3 class="font-medium text-gray-900">个人信息</h3>
                                <p class="text-sm text-gray-600">查看和编辑您的个人资料</p>
                            </div>
                        </div>
                    </div>

                    <div class="bg-green-50 rounded-lg p-6 shadow-sm hover:shadow transition-custom">
                        <a href="finamcial.html">
                            <div class="flex items-center">
                                <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-4">
                                    <i class="fa fa-book text-green-600 text-xl"></i>
                                </div>
                                <div>
                                    <h3 class="font-medium text-gray-900">我的账本</h3>
                                    <p class="text-sm text-gray-600">添加我的账本</p>
                                </div>
                            </div>
                        </a>
                    </div>
                </div>
                
                <div class="mt-8 pt-6 border-t border-gray-100">
                    <h3 class="font-medium text-gray-900 mb-4">最近活动</h3>
                    <div class="bg-gray-50 rounded-lg p-4 log-list"></div>
                </div>
            </div>
        </div>
    </main>
    <!-- 页脚 -->
    <footer class="bg-white border-t border-gray-200 mt-12" style="position: fixed;bottom:0px;width: 100%">
        <div class="container mx-auto px-4 py-6">
            <div class="text-center text-gray-500 text-sm">
                <p>© 2024 登录系统 - 版权所有</p>
            </div>
        </div>
    </footer>
    <script>
        $(function(){
            //检测用户是否已经登录，如果登录获取用户信息，如果没有登录则跳转至登录页
            $.post("controller/checklogin.php","",function(e){
                e = JSON.parse(e)
                if(e.code){
                    //初始化用户信息
                    $(".username").html(e.data.name); //展示用户名
                    $("body").show(); //显示页面内容
                }else{
                    //直接跳转至登录页
                    location.href = "login.html";
                }
            })
            //查询所有用户的活动
            $.post("controller/get_log.php","",function(e){
                e = JSON.parse(e);
                if(e.code) {
                    var str = "";
                    $(".log-list").html("")
                    e.data.forEach(function(item){
                        str += '<p class="text-sm text-gray-600"><i class="fa fa-clock-o text-gray-400 mr-2"></i> 您与' + item.log_times + '进行了"' + item.operation +'"操作。</p>';
                    })
                    $(".log-list").html(str);
                }
            })
            //退出登录
            $("#user_exit").on("click",function(){
                if(confirm("您确定要退出吗？")){
                    $.post("controller/logout.php","",function(e){
                        e = JSON.parse(e)
                        alert(e.msg);
                        location.href = "login.html"
                    })
                }
            })
        })
    </script>
</body>
</html>    